package artid.com.arttogo.adapter;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.fragment.CollectDetailFragment;

/**
 * ClassName:MatchFragmentAdapter <br/>
 * Function: 项目页适配器<br/>
 * Reason: 解决项目页标签可以左右滑动的功能 <br/>
 * Date: 2014-2-25 下午4:00:34 <br/>
 * 
 * @author ybq
 * @version
 * @since JDK 1.6
 * @see
 */
public class CollectDetFragmentAdapter extends FragmentStatePagerAdapter {

	private ArrayList<String> mList;
	private List<CollectDetailFragment> fragList;
	private ArrayList<String> mInsList = null;
	Boolean isFromOrgan =false;
	private String titileName;

	public CollectDetFragmentAdapter(FragmentManager fm, String titileName) {
		super(fm);
		fragList = new ArrayList<CollectDetailFragment>();
		this.titileName=titileName;
	}

	public void setData(ArrayList<String> list) {
		mList = list;
		notifyDataSetChanged();
	}

	public void setInsData(ArrayList<String> list) {
		mInsList = list;
		notifyDataSetChanged();
	}
	/**
	 * 机构进入设置，与普通的详情不一样
	 */
	public void setCodeMode(Boolean isFromOrgan) {
		this.isFromOrgan = isFromOrgan;
	}

	@Override
	public CollectDetailFragment getItem(int position) {
		return getFragments(position);
	}

//	public ShareItem getShareitem(int position) {
//		return fragList.get(position).getShareitem();
//	}
	
//	
//	public String getTitle(int position) {
//		return fragList.get(position).getShareitem().getTitle();
//	}
	
	
	
	@Override
	public Object instantiateItem(ViewGroup group, int position) {
		return super.instantiateItem(group, position);
	}

	private CollectDetailFragment getFragments(int position) {

		CollectDetailFragment fragment = new CollectDetailFragment(titileName);
		fragment.setArguments(getBundle(position));
		fragList.add(fragment);
		// return fragment;
		return fragment;
	}

	private Bundle getBundle(int position) {
		Bundle bundle = new Bundle();
		String id = "";
		if (mInsList!=null) {
			id = mInsList.get(position);
			bundle.putString("id", id);
		}else {
			id = mList.get(position);
			bundle.putString("id", id);
		}
		
		
		bundle.putBoolean("isOrg", isFromOrgan);
		return bundle;
	}

	@Override
	public int getCount() {
		if (mInsList!=null) {
			return mInsList.size();
		}
		return null == mList ? 0 : mList.size();
	}

	@Override
	public int getItemPosition(Object object) {
		return POSITION_NONE;
	}
}
